use super::*;

#[derive(Default, Debug)]
pub struct PrivateDict {
	pub local_subroutines_offset: Option<usize>,
	pub default_width: Option<f32>,
	pub nominal_width: Option<f32>,
}
impl PrivateDict {
	pub fn parse(data: &[u8]) -> Self {
		let mut dict = PrivateDict::default();
		let mut operands_buffer = [0.0; MAX_OPERANDS_LEN];
		let mut dict_parser = DictionaryParser::new(data, &mut operands_buffer);
		while let Some(operator) = dict_parser.parse_next() {
			if operator.get() == operator::LOCAL_SUBROUTINES_OFFSET {
				dict.local_subroutines_offset = dict_parser.parse_offset();
			} else if operator.get() == operator::DEFAULT_WIDTH {
				dict.default_width = dict_parser.parse_number().map(|n| n as f32);
			} else if operator.get() == operator::NOMINAL_WIDTH {
				dict.nominal_width = dict_parser.parse_number().map(|n| n as f32);
			}
		}

		dict
	}
}

/// Enumerates some operators defined in the Adobe Technical Note #5176,
/// Table 23 Private DICT Operators
mod operator {
	pub const LOCAL_SUBROUTINES_OFFSET: u16 = 19;
	pub const DEFAULT_WIDTH: u16 = 20;
	pub const NOMINAL_WIDTH: u16 = 21;
}
